rm(list = ls())

setwd('/path/to/replication/')

library(data.table)
library(ggplot2)

# Figure B8: Monthly-varying Covid-19 effects on Asian hate crimes

## Figure B8 (a)
if (!file.exists('./output/coeff_deaths_jan_backup.RData')) {
  source('./code/figure2areg.R')
}

coeffs <- get(load('./output/coeff_deaths_jan_backup.RData'))
ggplot(coeffs,aes(x = month, y = effect)) +
  geom_point(size=0.75) +
  geom_hline(yintercept = 0, colour='red', linetype='longdash', size=0.25) +
  geom_vline(xintercept=as.Date('01-01-2020', format='%m-%d-%Y'),
             color='blue', linetype='dashed') +
  annotate("text", x = as.Date('04-01-2019', format='%m-%d-%Y'), y = 0.01, label = "Covid-19", colour='blue') +
  geom_linerange(aes(ymin = ci_low, ymax = ci_high)) +
  scale_x_date(breaks = "6 month", minor_breaks = "1 month", date_labels = '%Y-%m',
               limits = c(min(coeffs$month), max = as.Date('05-01-2020', format='%m-%d-%Y')),
               expand=c(0,0)) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
        legend.position="none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"
        ),axis.title.y = element_text(size = rel(1.2)),axis.text.y=element_text(size=12)) +
  xlab(NULL) +
  ylab('Effect of health threat on Asian hate crimes')
ggsave('./parallel_trends_deaths_jan.pdf', width=7, height=6.5)

## Figure B8 (b)
if (!file.exists('./output/coeff_economic_loss_backup.RData')) {
  source('./code/figure2breg.R')
}

coeffs <- get(load('./output/coeff_economic_loss_backup.RData'))
ggplot(coeffs,aes(x = month, y = effect)) +
  geom_point(size=0.75) +
  geom_hline(yintercept = 0, colour='red', linetype='longdash', size=0.25) +
  geom_vline(xintercept=as.Date('01-01-2020', format='%m-%d-%Y'),
             color='blue', linetype='dashed') +
  annotate("text", x = as.Date('04-01-2019', format='%m-%d-%Y'), y = 0.0095, label = "Covid-19", colour='blue') +
  geom_linerange(aes(ymin = ci_low, ymax = ci_high)) +
  scale_x_date(breaks = "6 month", minor_breaks = "1 month", date_labels = '%Y-%m',
               limits = c(min(coeffs$month), max = as.Date('05-01-2020', format='%m-%d-%Y')),
               expand=c(0,0)) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
        legend.position="none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"
        ),axis.title.y = element_text(size = rel(1.2)),axis.text.y=element_text(size=12)) +
  xlab(NULL) +
  ylab('Effect of unemployment threat on Asian hate crimes')
ggsave('./parallel_trends_econ.pdf', width=7, height=6.5)